#!/usr/bin/env python3
import sys
import re

FILE_RAW = sys.argv[2]
FILE_RE = sys.argv[1]


TEXT = None
with open(FILE_RAW) as fp:
    TEXT = fp.read().split('\n')
    TEXT = [i.strip() for i in TEXT if i]

TE_RE = None
with open(FILE_RE) as fp:
	TE_RE = [i  for i in fp if i ]

res =set()
def p(i):
	if i not in res:
		print(i)
	res.add(i)


[[p(i) for i in TEXT if i.split()[0].find(ii.split()[1]) != -1]
	for ii in TE_RE]


# for i in res:
	# print(i)

